﻿@{
    ViewBag.Title = "City Maintenance";
    LineFocus.Nikcron.Models.Lookup Countries = ViewBag.Countries;
    LineFocus.Nikcron.Models.Lookup States = ViewBag.States;
}

@model Nickron.Database.City

@using (Html.BeginForm("CityMaintenance", "Master", FormMethod.Post, new { onsubmit = "return ValidateForm();" }))
{ 
    <div class="col-md-12">

        <div class="box box-danger">
            <div class="box-body">

                <div class="form-group">
                    <label> Country:</label>
                    <div class="input-group">
                        <div class="input-group-addon">
                            <i></i>
                        </div>
                        <select id="Country" name="Country" class="selectpicker show-tick" title="Select Country">
                            @Html.Partial("Dropdown", Countries)
                        </select>
                    </div><!-- /.input group -->
                </div><!-- /.form group -->

                <div class="form-group">
                    <label> State:</label>
                    <div class="input-group">
                        <div class="input-group-addon">
                            <i></i>
                        </div>
                        <select id="State" name="State" class="selectpicker show-tick" title="Select State">
                            @Html.Partial("Dropdown", States)
                        </select>
                    </div><!-- /.input group -->
                </div><!-- /.form group -->

                <div class="form-group">
                    <label> City:</label><span class="astrisk">*</span>
                    <div class="input-group">
                        <div class="input-group-addon">
                            <i class=""></i>
                        </div>
                        <input id="City" name="City" type="text" maxlength="50" class="form-control pull-right" />
                    </div><!-- /.input group -->
                </div><!-- /.form group -->

                <div class="box-footer">
                    <input type="hidden" name="Id" id="Id" value="@ViewBag.Id" />
                    <button type="submit" class="btn btn-primary" style=" width:80px;">Save</button>
                    <button type="reset" class="btn btn-primary" style=" width:80px;">Cancel</button>
                </div>

            </div><!-- /.box-body -->
        </div><!-- /.box -->
    </div><!-- /.col (left) -->

}

<script type="text/javascript">

    function ValidateForm() {
        RequiredDropdown("Country", -1, "Select a Country");
        RequiredDropdown("State", -1, "Select a State");
        RequiredTextbox("City", "Enter the City Name");
        return AlertError();
    }
  
    $('#Country').change(function () {
        $('.Country').removeAttr("disabled");
        $('.Country').prop("disabled", "true");
        $('.Country_' + $('#Country').val()).removeAttr("disabled");
        $('#State').removeAttr("disabled");
        $('#State').selectpicker('deselectAll');
        $('#State').selectpicker("render");
        $('#State').selectpicker("refresh");
        $('#State')[0].selectedIndex = -1;
        $('*[data-id="State"]').prop("title", "");
        $('*[data-id="State"]').html('<span class="filter-option pull-left" />&nbsp;<span class="caret" />');
    });

    $(document).ready(function () {
        $('.selectpicker').selectpicker();
      
        if ("@ViewBag.Id" != "") {
            $('#Country').selectpicker("val", "@Model.StateId");
            $('#State').selectpicker("val", "@Model.StateId");
            $('#City').val("@Model.Name");           
        }       
    });
</script>

@{
    var message = TempData["AlertMessage"] ?? string.Empty;
}

<script type="text/javascript">
    var message = '@message';
    if(message)
        alert(message);
</script>

<script>
    $(document).ready(function () {
    var url = "";

    if ('@TempData["msg"]' != "") {
    $("#dialog-alert").dialog('open');
    }
    $("#dialog-confirm").dialog({
    autoOpen: false,
    resizable: false,
    height: 170,
    width: 350,
    show: { effect: 'drop', direction: "up" },
    modal: true,
    draggable: true,
    open: function (event, ui) {
    $(".ui-dialog-titlebar-close").hide();
    },
    buttons: {
    "OK": function () {
    $(this).dialog("close");
    window.location.href = url;
    },
    "Cancel": function () {
    $(this).dialog("close");
    }
    }
    });

    $("#lnkDelete").live("click", function (e) {
    // e.preventDefault(); use this or return false
    url = $(this).attr('href');
    $("#dialog-confirm").dialog('open');

    return false;
    });
    });
</script>